<?php
namespace app\api\middleware;
use think\Request;

class AuthMiddleware
{
    public static function rend(){
        $data = \request()->param();
        if(!isset($data['sign'])||empty($data['sign'])){
            return [false,'签名不存在'];
        }
        $sign = $data['sign'];
        unset($data['sign']);
        $newsign = self::getSign($data);
//        echo '<pre>';
//        print_r($newsign);
//        exit;
        if($sign===$newsign){
            return [true,''];
        }
        return [false,'签名错误'];
    }
    public static function getSign($array){
        if(empty($array)){
            $array = "{}";
        }else{
            ksort($array);
            $array = json_encode($array,JSON_UNESCAPED_UNICODE);
        }
        $str = $array.config('api.key');
        return md5($str);
    }
}